package com.example.designpatterns.Strategy;

import com.example.designpatterns.Strategy.Cash.CashFactory;
import com.example.designpatterns.Strategy.Cash.CashSuper;

import java.util.Scanner;

/**
 * @author HUAWEI
 * 收银软件版本v1.0
 */
public class CashSoftware02 {
    public static void main(String[] args) {
        // 商品的单价
        double price = 0;
        // 商品的数量
        int num = 0;
        // 当前商品所需支付的价格
        double currentPrice = 0;
        // 商品的总价
        double totalPrice = 0;
        int discountType = 0;
        Scanner sc = new Scanner(System.in);
        do {
            System.out.println("请输入商品的价格：");
            price = Double.parseDouble(sc.nextLine());
            System.out.println("请输入商品的数量：");
            num = Integer.parseInt(sc.nextLine());
            System.out.println("请输入促销策略：");
            discountType = Integer.parseInt(sc.nextLine());
            CashSuper cashSuper = CashFactory.createCashSuper(discountType);
            currentPrice = cashSuper.acceptCash(price, num);
            totalPrice += currentPrice;
        } while (price > 0 && num > 0);
        System.out.println("总价：" + totalPrice);
    }
}
